﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RoomPriceEntity;
using CommonUtility;

namespace PriceCacheDownloader
{
    public class RequestCreater
    {
        private string hotelCodes;
        private DateTime arrival;
        private DateTime departure;
        private List<string> hotelCodeList;

        public RequestCreater(string hotelCodes)
        {
            this.hotelCodes = hotelCodes;
        }

        public RequestCreater(List<string> hotelCodeList)
        {
            this.hotelCodeList = hotelCodeList;
        }

        public void SetArrival(DateTime dt)
        {
            arrival = dt;
        }

        public void SetDeparture(DateTime dt)
        {
            departure = dt;
        }

        public string GetAgodaRequestXml()
        {
            string arrivalstr = arrival.ToString("yyyy-MM-dd");
            string departurestr = departure.ToString("yyyy-MM-dd");

            return string.Format(@"<?xml version=""1.0"" encoding=""utf-8"" ?>
<AvailabilityRequestV2 siteid=""1555669"" apikey=""C954C13C-1FCF-4A66-981C-DE194A16BF96"" async=""false"" waittime=""60"" xmlns=""http://xml.agoda.com"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"">
  <Type>6</Type>
  <Id>{0}</Id>
  <Radius>0</Radius>
  <Latitude>0</Latitude>
  <Longitude>0</Longitude>
  <CheckIn>{1}</CheckIn>
  <CheckOut>{2}</CheckOut>
  <Rooms>1</Rooms>
  <Adults>1</Adults>
  <Children>0</Children>
  <Rateplan>Retail</Rateplan>
  <Language>zh-cn</Language>
  <Currency>USD</Currency>
</AvailabilityRequestV2>"
                         , hotelCodes, arrivalstr, departurestr);
        }

        public string GetBookingRequestXmlBody()
        {
            BookingHotelAvlRequestEntity entity = new BookingHotelAvlRequestEntity()
            {
                arrival_date = arrival.ToString("yyyy-MM-dd"),
                departure_date = departure.ToString("yyyy-MM-dd"),
                languagecode = "zh",
                show_extra_charges = 1,
                show_test = 1,
                hotel_ids = hotelCodeList,
                currency_code = "USD"
            };

            string postData = JsonHelper.JsonSerializer(entity);

            return postData;
        }

        public string GetBookingIsHotelXmlBody()
        {
            BookingGetHotelRequestEntity entity = new BookingGetHotelRequestEntity()
            {
                hotel_ids = hotelCodeList,
                fields = "hotel_id,hoteltype_id"
            };
            string postData = JsonHelper.JsonSerializer(entity);

            return postData;
        }
    }
}
